package com.ruoqing.inform.service.message;

import com.ruoqing.core.constant.Constants;
import com.ruoqing.core.dto.user.UserMessageDto;
import com.ruoqing.inform.constant.qqmail.QqEmailConstantEnum;
import com.ruoqing.inform.service.api.MailMessageService;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
	* @author YaoXian
	* @title: UserSmsServiceImpl
	* @projectName ruoxi-blog
	* @description: 若兮微服务 - 通知服务 - 用户服务模块 - 异步接收队列消息发送通知
	* @date 2020-12-03 19:17
	*/
@Slf4j
@Service
@RocketMQMessageListener(consumerGroup = "ruoqing-inform-userMsgConsumer-group", topic = "user_topic")
public class UserSmsServiceImpl implements RocketMQListener<UserMessageDto>{
		
		@Resource
		private MailMessageService mailMessageService;
		
		/**
			* 订阅消息队列中可靠异步消息
			* 根据条件异步解耦执行方法
			* @param userMessageDto
			*/
		@SneakyThrows
		@Override
		public void onMessage(UserMessageDto userMessageDto) {
				if (Constants.responseOk.equals(userMessageDto.getUserResponse().getStatus())){
						switch (userMessageDto.getModule()){
								case register:
										mailMessageService.sendMailMessage(QqEmailConstantEnum.sender.getContent(),
														userMessageDto.getUserResponse().getUserEntity().getEmail(),
														QqEmailConstantEnum.emailTitle.getContent(),
														"尊敬的"+userMessageDto.getUserResponse().getUserEntity().getUsername()+",恭喜您!在若兮博客中注册成功!");
										break;
								default:
										log.error("错误的用户通知参数类型!");
						}
				}
		}
}
